﻿#pragma once
#include <map>
#include <string>
#include <vector>
#include <memory>

//tool tree node
class ToolTreeNode
{
public:
	using Child = std::pair<std::shared_ptr<ToolTreeNode>, int>;
	using Children = std::vector<Child>;
	ToolTreeNode(const std::string& name, const Children& children);
	void addChildren(const Child& child);
	std::string getName() const;
	Children getChildren() const;

private:
	std::string m_name;
	Children m_children;
};

class ComposedTable
{
	using ToolName = std::string;	//The composed tool's name
	using MaterialName = std::string;	//material name
	using Material_Num = std::pair<MaterialName, int>;	//one of the composed material's name and number
	using MaterialList = std::vector<Material_Num>;	//Material list of composed requirement
public:
	ComposedTable(const char* filename);
	void printResult() const;
	void addProp(const ToolName& toolName, int num = 1);
	std::vector<std::string> splitString(const std::string& inputStr, const char split = ' ');

private:
	std::string calcCompositeBaseMaterial(const ToolName& toolName);
	void convertResult(const std::string& input);
	void extractResultFromStr(const std::string& inputStr);

private:
	std::map<ToolName, std::shared_ptr<ToolTreeNode>> m_mapToolTreeNode;
	std::map<ToolName, int> m_mapToolID;
	std::map<ToolName, int> m_mapTarget;
	std::map<MaterialName, int> m_mapResult;
};

